# This file extends the init.sh (provided by gnulib).

# Set environment variables for the tests.
. ../tests/init-env

prepare_locale_ ()
{
  # Solaris 11 doesn't strip the CODESET part from the locale name,
  # when looking for a message catalog.  Create a directory link with
  # CODESET, to work around this.
  if test "$1" != "$2" && test "$GLIBC2" = no; then
    case "$host_os" in
      solaris2.11)
        cp -R "$1" "$2"
        ;;
    esac
  fi
}

# func_filter_POT_Creation_Date inputfile outputfile
# creates outputfile from inputfile, filtering out any 'POT-Creation-Date' line.
func_filter_POT_Creation_Date ()
{
  # A simple "grep -v 'POT-Creation-Date'" does not work:
  # - GNU grep 2.24 produces "Binary file (standard input) matches" in the
  #   output. The workaround is to use option '--text'.
  # - Similarly, OpenBSD 4.0 produces "Binary file (standard input) matches"
  #   in the output, but here it can be worked around by giving the input
  #   through a pipe.
  # - On native Windows, some 'grep' binaries produce CRLF line endings. Filter
  #   out the CRs a posteriori.
  cat "$1" | LC_ALL=C grep --text -v 'POT-Creation-Date' > "$1".tmq 2>/dev/null \
    || cat "$1" | LC_ALL=C grep -v 'POT-Creation-Date' > "$1".tmq \
    || Exit 1
  LC_ALL=C tr -d '\r' < "$1".tmq > "$2" || Exit 1
}
